package com.cskaoyan.controller;

import com.cskaoyan.bo.PermissionBo;
import com.cskaoyan.service.PermissionServiceImpl;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.permission.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class PermissionController {

    @Autowired
    PermissionServiceImpl permissionService;

    @RequestMapping(value = "admin/role/permissions", method = RequestMethod.POST)
    public BaseRespVo list(@RequestBody PermissionBo permissionBo) {

        int i = permissionService.updatePermission(permissionBo);

        if (i == 404) {
            return BaseRespVo.error("权限授权失败");
        }
        return BaseRespVo.ok("权限授权成功");
    }

    @RequestMapping(value = "admin/role/permissions", method = RequestMethod.GET)
    public BaseRespVo list(Integer roleId) {

        PermissionVo permissionVo = permissionService.getPermission(roleId);
        return BaseRespVo.ok(permissionVo);
    }
}
